import { Vue, Component, Prop, Provide, Emit, Watch } from 'vue-property-decorator';
import { Subject } from 'rxjs';
import { CreateElement } from 'vue';
import './apply-apply-wfexp-view.less';
import ApplyService from '@widgets/apply/apply-service';


import view_expbar from '@widgets/apply/apply-wfexp-viewexpbar-wfexpbar/apply-wfexp-viewexpbar-wfexpbar';

@Component({
    components: {
        view_expbar, 
    },
    beforeRouteEnter: (to: any, from: any, next: any) => {
        next((vm: any) => {
            vm.$store.commit('addCurPageViewtag', { fullPath: to.fullPath, viewtag: vm.viewtag });
        });
    },
})
export default class ApplyApply_WFExpView extends Vue {

    /**
     * 实体服务对象
     *
     * @type {ApplyService}
     * @memberof ApplyApply_WFExpView
     */
    public entityService: ApplyService = new ApplyService();

    /**
     * 数据变化
     *
     * @param {*} val
     * @returns {*}
     * @memberof ApplyApply_WFExpView
     */
    @Emit() 
    public viewDatasChange(val: any):any {
        return val;
    }

    /**
     * 数据视图
     *
     * @type {string}
     * @memberof ApplyApply_WFExpView
     */
    @Prop() public viewdata!: string;

	/**
	 * 视图标识
	 *
	 * @type {string}
	 * @memberof ApplyApply_WFExpView
	 */
	public viewtag: string = '63cd54bd05fc05f780a81afce5f84af0';

    /**
     * 父数据对象
     *
     * @protected
     * @type {*}
     * @memberof ApplyApply_WFExpView
     */
    protected srfparentdata: any = {};

    /**
     * 视图模型数据
     *
     * @type {*}
     * @memberof ApplyApply_WFExpView
     */
    public model: any = {
        srfTitle: '申请工作流导航视图(申请流程)',
        srfCaption: 'apply.views.apply_wfexpview.caption',
        srfSubCaption: '',
        dataInfo: ''
    }

    /**
     * 处理值变化
     *
     * @param {*} newVal
     * @param {*} oldVal
     * @memberof ApplyApply_WFExpView
     */
    @Watch('viewdata')
    onViewData(newVal: any, oldVal: any) {
        const _this: any = this;
        if (!Object.is(newVal, oldVal) && _this.engine) {
            _this.engine.setViewData(newVal);
            _this.engine.load();
        }
    }

    /**
     * 容器模型
     *
     * @type {*}
     * @memberof ApplyApply_WFExpView
     */
    public containerModel: any = {
        view_expbar: { name: 'expbar', type: 'WFEXPBAR' },
        wflinks: [],
    };

    /**
     * 视图状态订阅对象
     *
     * @private
     * @type {Subject<{action: string, data: any}>}
     * @memberof ApplyApply_WFExpView
     */
    public viewState: Subject<ViewState> = new Subject();



    /**
     * 引擎初始化
     *
     * @private
     * @memberof ApplyApply_WFExpView
     */
    private engineInit(): void {
    }

    /**
     * Vue声明周期
     *
     * @memberof ApplyApply_WFExpView
     */
    public created() {
        const secondtag = this.$util.createUUID();
        this.$store.commit('viewaction/createdView', { viewtag: this.viewtag, secondtag: secondtag });
        this.viewtag = secondtag;
        
    }

    /**
     * 销毁之前
     *
     * @memberof ApplyApply_WFExpView
     */
    public beforeDestroy() {
        this.$store.commit('viewaction/removeView', this.viewtag);
    }

    /**
     * Vue声明周期(组件初始化完毕)
     *
     * @memberof ApplyApply_WFExpView
     */
    public mounted() {
        const _this: any = this;
        _this.engineInit();
        if (_this.loadModel && _this.loadModel instanceof Function) {
            _this.loadModel();
        }
        
    }




    /**
     * 关闭视图
     *
     * @param {any[]} args
     * @memberof ApplyApply_WFExpView
     */
    public closeView(args: any[]): void {
        let _view: any = this;
        if (_view.viewdata) {
            _view.$emit('viewdataschange', args);
            _view.$emit('close');
        } else if (_view.$tabPageExp) {
            _view.$tabPageExp.onClose(_view.$route.fullPath);
        }
    }


    /**
     * 绘制视图消息 （上方）
     *
     * @returns
     * @memberof ApplyApply_WFExpView
     */
    public renderPosTopMsgs() {
        return (
            <div class='view-top-messages'>
            </div>
        );
    }

    /**
     * 绘制视图消息 （下方）
     *
     * @returns
     * @memberof ApplyApply_WFExpView
     */
    public renderPosBottomMsgs() {
        return (
            <div class='view-bottom-messages'>
            </div>
        );
    }
    
    /**
     * 绘制内容
     *
     * @param {CreateElement} h
     * @returns
     * @memberof ApplyApply_WFExpView
     */
    public render(h: CreateElement) {
        return (
        <div class="view-container apply-apply-wfexp-view">
            <card class='view-card' dis-hover={true} padding={0} bordered={false}>
                <p slot="title">
                    申请
                </p>
                <div class="content-container">
                    <view_expbar 
                        viewState={this.viewState} 
                        name='expbar' 
                        ref='expbar' 
                        on-closeview={($event: any) => this.closeView($event)}>
                    </view_expbar>
                </div>
            </card>
        </div>
        );
    }

}